package com.wlb365.financing.modules.orgaccount.controller;

import com.wlb365.financing.common.dto.R;
import com.wlb365.financing.modules.orgaccount.request.OrgAccountAddReq;
import com.wlb365.financing.modules.orgaccount.request.OrgAccountQueryPageReq;
import com.wlb365.financing.modules.orgaccount.response.OrgAccountAddRes;
import com.wlb365.financing.modules.orgaccount.response.OrgAccountPageRes;
import com.wlb365.financing.modules.orgaccount.service.IOrgAccountService;
import com.wlb365.financing.modules.sys.entity.Dept;
import com.wlb365.financing.modules.sys.service.IDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Author LuHang
 * @Date 2021/5/24 15:53
 * @Version 1.0
 */
@RestController
@RequestMapping("orgAccount")
public class OrgAccountController {

    @Autowired
    private IDeptService deptService;

    @Autowired
    private IOrgAccountService orgAccountService;

    /**
     * 账号列表
     * @return
     */
    @RequiresPermissions("orgAccount:supplier:accountView")
    @GetMapping(value = "supplier/accountView")
    public ModelAndView accountView(final String compId){
        ModelAndView modelAndView = new ModelAndView("orgaccount/org_supplier_account_list");
        modelAndView.addObject("compId",compId);
        return modelAndView;
    }

    /**
     * 供应商融资账号管理页面
     * @return
     */
    @RequiresPermissions("orgAccount:supplier:index")
    @GetMapping(value = "supplier/index")
    public ModelAndView supplierIndex(){
        ModelAndView modelAndView = new ModelAndView("orgaccount/org_supplier");
        return modelAndView;
    }

    /**
     * 供应商授信通过视图
     * @return
     */
    @RequiresPermissions("orgAccount:supplier:adoptBankView")
    @GetMapping(value = "supplier/adoptBankView")
    public ModelAndView adoptBankView(final String compId){
        ModelAndView modelAndView = new ModelAndView("orgaccount/org_supplier_adopt_bank");
        modelAndView.addObject("compId",compId);
        return modelAndView;
    }

    /**
     * 供应商新增视图
     * @param compId 供应商id
     * @param bankId 银行id
     * @return
     */
    @RequiresPermissions("orgAccount:supplier:addView")
    @GetMapping(value = "supplier/addView")
    public ModelAndView addView(final String compId,final String bankId){
        ModelAndView modelAndView = new ModelAndView("orgaccount/org_supplier_edit");
        Dept dept =  deptService.getById(bankId);
        modelAndView.addObject("compId",compId);
        modelAndView.addObject("bankId",bankId);
        modelAndView.addObject("dept",dept);
        return modelAndView;
    }

    /**
     * 新增供应商账号
     * @param orgAccountAddReq
     * @return
     */
    @PostMapping(value = "supplier/add")
    public R add (final OrgAccountAddReq orgAccountAddReq){
        orgAccountService.add(orgAccountAddReq);
        return R.ok();
    }

    /**
     * 账号列表
     * @return
     */
    @GetMapping(value = "supplier/listData")
    public OrgAccountPageRes listData(OrgAccountQueryPageReq orgAccountPageRes){
        return orgAccountService.listData(orgAccountPageRes);
    }
}
